When input data such as a picture are encoded, in an encoding method such as a moving picture experts group 2 (MPEG2), the quantity of codes generated in every group of pictures (GOP) is required to be controlled in units of encoding processing, for example, GOP, for the limitation such as package media and a capacity for communication, so that the above quantity is within the predetermined target quantity of codes.
There is difference between the target quantity of codes and the quantity of generated codes because quantization is discrete or the like, the difference resulting in the deterioration of the quality of a picture. Generally, to solve such a problem, a feedback control method of observing difference between the target quantity of codes and the quantity of generated codes, reflecting a differential value in the target quantity of codes of input data to be encoded after the observation and bringing the quantity of generated codes as close to the target quantity of codes as possible and others, is adopted.
FIG. 31 is a system diagram showing the main part of a conventional type encoder for executing such processing. For input data, image data are shown.
Input data supplied to a terminal 11 are supplied to discrete cosine transform (DCT) means 12 and is transformed to a DCT coefficient. The DCT coefficient is supplied to fixed quantizing means 14 and is quantized. In the quantizing means 14, plural quantizers, each of which is different in a quantized value, are provided. In the case of MPEG2, 31 quantized values are generated as a result of quantization, however, as the quantizing means 14 is used for calculating the optimum target quantity of codes, the smaller number of quantizers are actually used.
In this example, N (for example, N=8) pieces of quantizers 14a to 14h, each of which is different in a quantized value, are used as shown in FIG. 32. The quantity of generated codes of a quantized DCT coefficient is calculated in arithmetic means 16 in the respective quantized values of units of GOP and of units of macro block that is the minimum unit of encoding. Therefore, this arithmetic means 16 is also composed of eight arithmetic units 16a to 16h, as shown in FIG. 32.
The quantity of generated codes in units of GOP and in units of macro block is supplied to target code quantity allocating means (target code quantity determining means) 18 and the target quantity of codes TMB (TMBb) to be the quantity of codes every macro block (a target bit rate) is allocated based upon the predetermined target quantity of codes TMB in units of GOP.
The target quantity of codes TMBb and the DCT coefficient are supplied to Q search means 30 and then the minimum quantized value not exceeding the target quantity of codes TMB acquired every macro block is acquired by an operation. The minimum quantized value and the DCT coefficient are supplied to back search means 32. The means 32 is a block processed according to back search algorithm for preventing the quality of a picture from being deteriorated in encoding/decoding and in the means, a final quantized value for quantization is selected.
The quantized value is supplied to quantizing means 34 and a DCT coefficient is quantized. The quantized DCT coefficient is converted to a variable length code VLC according to the frequency of generation by variable length coding means 36.
As quantization for a DCT coefficient is discrete or a quantized value selected by the Q search means 30 is replaced with a quantized value when the back search algorithm of the back search means 32 is first encoded, the target quantity of codes TMB allocated by the target code quantity allocating means 18 and the quantity of generated codes every macro block generated by the variable length coding means 36 are not necessarily equal.
Therefore, the variable length coding means 36 further feeds a differential value DF between the target quantity of codes TMB every macro block and the actual quantity of generated codes back to the target code quantity allocating means 18.
The quantity of generated codes is brought closer to the target quantity of codes by adding the differential value DF in units of GOP which is the same unit as the target quantity of codes and adding the added differential value to the target quantity of codes TMB of a macro block to be encoded after that in units of GOP.
FIG. 33 shows a concrete example of the target code quantity allocating means 18. As shown in FIG. 33, interpolating means 22 judges which of the quantity of generated codes in units of GOP respectively from eight fixed quantizers 14a to 14h the target quantity of codes TMB in units of GOP is, and it interpolates and outputs the minimum quantized value not exceeding the target quantity of codes.
An allocator 24 allocates the target quantity of codes TMBa every macro block based upon a quantized value acquired by interpolation processing and the quantity of generated codes in units of macro block from two fixed quantizers respectively adjacent to the above quantized value. Actually, the allocator acquires the target quantity of codes every macro block by calculation.
Feedback quantity determining means 26 adds a differential value DF from the variable length coding means 36 in units of GOP which is the same unit as the unit of the target quantity of codes. Adding output DF is output until the value exceeds a feedback threshold FBT (a fixed value). As a limiter is operated when the value exceeds the feedback threshold FBT, a fixed feedback threshold FBT is output.
Adding means 28 outputs a value acquired by adding a feedback value FB to the target quantity of codes TMBa every macro block to be encoded after that in units of GOP which is the same unit as the target quantity of codes, as the target quantity of codes TMBb every macro block.
Heretofore, as a fixed feedback threshold FBT is used, the quantity of generated codes in units of GOP never exceeds the target quantity of codes TMBb. This is because the target code quantity allocating means 24 allocates the target quantity of codes to all macro blocks in each GOP.
Feedback quantity means quantity acquired by limiting with a feedback threshold FBT the difference DF, added every GOP which is the same unit as the target quantity of codes, between the target quantity of codes TMBa allocated every macro block and the quantity of generated codes quantized at a quantized value not exceeding the target quantity of codes. As long as the interpolating means 22 selects the minimum quantized value not exceeding the target quantity of codes in units of GOP, the quantity of generated codes in units of GOP never exceeds the target quantity of codes even if such feedback control is executed.
As described above, in the conventional type encoding method, as a threshold is determined independent of the character of input image data though the threshold can be set as a feedback value from an external device, there is a problem that the quality of a picture is remarkably deteriorated when encoding/decoding is repeated.
The present invention is made to solve such conventional type problems and the object is to provide an encoding method and an encoder using it in which the quality of a picture is never deteriorated even if encoding/decoding is repeated.